package com.example.springt334.dao.impl;

import com.example.springt334.dao.UserDao;
import com.example.springt334.dao.UserService;
import com.example.springt334.dao.factory.UserDaoFactory;
import com.example.springt334.entity.User;

/**
 * 用户模块业务层实现
 */
public class UserServiceImpl implements UserService {
    //实例化所依赖的UserDao对象
    //private UserDao dao=new UserDaoImpl();

    //通过工厂获取所依赖的UserDao对象
    //private UserDao dao= UserDaoFactory.getInstance();

    /**
     * 声明接口类型的引用，和具体实现类解耦合
     */
    private UserDao userDao;

    /**
     * 保存用户信息
     * @param user
     */
    @Override
    public void save(User user) {
        //调用UserDao的方法保存用户信息
        userDao.save(user);
    }

    /**
     * dao属性的setter访问器，会被Spring调用，实现依赖注入
     */
    public void setUserDao(UserDao userDao){
        this.userDao=userDao;
    }
}
